/**
 *@Time    : 2021/11/8 23:51
 *@Author  : Shuai Jhou
 *@File    : client
 *@Software: GoLand
 * protoc --go_out=plugins=grpc:. ./proto/*.proto
 */

package main

import (
	"context"
	"flag"
	pb "go.zhoushuai.cn/go-programming-tour-book/grpc-demo/proto"
	"google.golang.org/grpc"
	"log"
)

var port string

func init() {
	flag.StringVar(&port, "p", "8000", "启动端口号")
	flag.Parse()
}

func main() {
	conn, _ := grpc.Dial(":"+port, grpc.WithInsecure())
	defer conn.Close()

	client := pb.NewGreeterClient(conn)
	_ = SayHello(client)
}

func SayHello(client pb.GreeterClient) error {
	resp, _ := client.SayHello(context.Background(), &pb.HelloRequest{Name: "Jhou Shuai"})
	log.Printf("client.SayHello resp: %s", resp.Message)
	return nil
}
